package edu.gatech.cc.hwa.server.features;

import java.util.Calendar;

import edu.gatech.cc.hwa.server.Profile;

public class DayOfWeekFeature extends Feature {

	public static final int ANY = -1;
	public static final int WEEKDAY = 0;
	public static final int WEEKEND = 1;
	
	private long time;
	
	public DayOfWeekFeature() {
		super(System.currentTimeMillis()+"");
		time = Long.parseLong(getRawData());
	}

	@Override
	public boolean matchesProfile(Profile profile) {
		int profileDay = profile.getDayOfWeek();
		return (profileDay == ANY) || profileDay == mapToId();
	}
	
	public int mapToId() {
		return maptoId(time);
	}

	public static int maptoId(long time) {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(time);
		int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
		if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) 
			return WEEKEND;
		else 
			return WEEKDAY;
	}
}
